﻿using System;
using CommunityToolkit.Mvvm.ComponentModel;
using System.Runtime.CompilerServices;
using System.ComponentModel;


namespace FixtureManageSystem.Models
{
    public class Employee : ObservableObject
    {

        /// 工号
        private string personNo = String.Empty;
        public string PersonNo
        {
            get
            {
                return personNo;
            }
            set
            {
                SetProperty(ref personNo, value);
            }
        }

        private int _id;
        public int ID { 
            get => _id;
            set => SetProperty(ref _id, value);
        }

        /// <summary>
        /// 姓名
        /// </summary>
        private string name = String.Empty;
        public string Name
        {
            get
            {
                return name;
            }
            set
            {
                if (value != this.name)
                {
                    name = value;
                    SetProperty(ref name, value);
                }
            }
        }

        /// <summary>
        /// 工厂
        /// </summary>
        /// <param name="factory"></param>

        private string factory = String.Empty;
        public string Factory
        {
            get
            {
                return factory;
            }
            set
            {
                if (value != this.factory)
                {
                    SetProperty(ref factory, value);
                }
            }
        }


        /// <summary>
        /// 联系方式
        /// </summary>
        /// <param name="tel"></param>

        private string tel = String.Empty;
        public string Tel
        {
            get
            {
                return tel;
            }
            set
            {
                if (value != this.tel)
                {
                    SetProperty(ref tel, value);
                }
            }
        }

        /// <summary>
        /// 部门
        /// </summary>
        /// <param name="departMent"></param>

        private string department = String.Empty;
        public string Department
        {
            get
            {
                return department;
            }
            set
            {
                if (value != this.department)
                {
                    SetProperty(ref department, value);
                }
            }
        }


        // 名字与id拼起来，方便搜索用的
        public string SearchName
        {
            get => $"{Name}({PersonNo})";
        }

        public override bool Equals(object obj)
        {
            if (obj == null || !(obj is Employee))
                return false;

            Employee other = (Employee)obj;

            return ID == other.ID && Name == other.Name && PersonNo == other.PersonNo && Department == other.Department
                 && Tel == other.Tel && Factory == other.Factory;                ;
        }

        public static bool operator ==(Employee s1, Employee s2)
        {
            if (object.ReferenceEquals(s1, s2))
                return true;

            if ((object)s1 == null || (object)s2 == null)
                return false;

            return s1.Equals(s2);
        }

        public static bool operator !=(Employee s1, Employee s2)
        {
            return !(s1 == s2);
        }

    }
}
